package com.example.hdwx.myapplication.json.found_json;

import android.util.Log;

import com.example.hdwx.myapplication.eneity.found_eneitys.FoundCarouselEneity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 发现轮播图解析
 */

public class FoundCarouselJSON {
   static String TAG="FoundCarouselJSON" ;
    public static List<FoundCarouselEneity> getCarouse(String response) {
        List<FoundCarouselEneity> dataC = new ArrayList<>();
        JSONObject object = null;
        try {
            object = new JSONObject(response);
            JSONArray array = object.getJSONArray("-1");
            for (int k = 0; k < array.length(); k++) {
                FoundCarouselEneity eneity = new FoundCarouselEneity();
                JSONObject object3 = array.getJSONObject(k);
                eneity.setImage_url(object3.optString("image_url"));

                eneity.save();
                if(eneity.save()){
                    Log.e(TAG,"FoundCarouselJSON数据存储成功");
                }else {
                    Log.e(TAG,"FoundCarouselJSON数据存储失败");
                }
                //轮播图加入集合
                dataC.add(eneity);
            }
            return dataC;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
